/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * cadPessoa.java
 *
 * Created on 01/07/2011, 17:54:41
 */

package projetolions;

import com.toedter.calendar.JDateChooser;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.ImageIcon;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;

/**
 *
 * @author rti dev-01
 */
public class cadPessoa extends javax.swing.JFrame {


    /** Creates new form cadPessoa */
    public cadPessoa() {
        initComponents();
        this.jtfNomePai.setVisible(false);
        this.jtfNomeMae.setVisible(false);
        this.jlNomePai.setVisible(false);
        this.jlNomeMae.setVisible(false);
        this.jtfNomeCompleto.requestFocus();
        this.jlImagem.setIcon(new ImageIcon("C:/Users/rti dev-01/Documents/NetBeansProjects/ProjetoLions/src/projetolions/Imagemm.png"));
        Date dat = new Date();
        this.jdcDataNascimento.setDate(dat);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jfcImagem = new javax.swing.JFileChooser();
        jpCadPessoa = new javax.swing.JPanel();
        jbNovo = new javax.swing.JButton();
        jbConsultar = new javax.swing.JButton();
        jbSalvar = new javax.swing.JButton();
        jbExcluir = new javax.swing.JButton();
        jbAnterior = new javax.swing.JButton();
        jbInicio = new javax.swing.JButton();
        jbProximo = new javax.swing.JButton();
        jbFinal = new javax.swing.JButton();
        jlNomeCompleto = new javax.swing.JLabel();
        jtfNomeCompleto = new javax.swing.JTextField();
        jtfEndereco = new javax.swing.JTextField();
        jlEndereço = new javax.swing.JLabel();
        jtfBairro = new javax.swing.JTextField();
        jlBairro = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jlRG = new javax.swing.JLabel();
        jlCidade = new javax.swing.JLabel();
        jtfCidade = new javax.swing.JTextField();
        jlCep = new javax.swing.JLabel();
        jtfCep = new javax.swing.JTextField();
        jlDataNascimento = new javax.swing.JLabel();
        jlSexo = new javax.swing.JLabel();
        jcbSexo = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jtfEmail = new javax.swing.JTextField();
        jlTelefone = new javax.swing.JLabel();
        jlNomePai = new javax.swing.JLabel();
        jtfNomePai = new javax.swing.JTextField();
        jlNomeMae = new javax.swing.JLabel();
        jtfNomeMae = new javax.swing.JTextField();
        jbImagem = new javax.swing.JButton();
        jtfCpf = new javax.swing.JFormattedTextField();
        jtfRg = new javax.swing.JFormattedTextField();
        jlImagem = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jlDeMenor = new javax.swing.JLabel();
        jdcDataNascimento = new com.toedter.calendar.JDateChooser();
        jtfTelefone = new javax.swing.JFormattedTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Controle de Pessoas");

        jbNovo.setText("Novo");
        jbNovo.setToolTipText("Novo");

        jbConsultar.setText("Consultar");
        jbConsultar.setToolTipText("Consultar");

        jbSalvar.setText("Salvar");
        jbSalvar.setToolTipText("Salvar");
        jbSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Salvar(evt);
            }
        });

        jbExcluir.setText("Excluir");
        jbExcluir.setToolTipText("Excluir");

        jbAnterior.setText("<");
        jbAnterior.setToolTipText("Voltar");

        jbInicio.setText("<<");
        jbInicio.setToolTipText("Primeira");

        jbProximo.setText(">");
        jbProximo.setToolTipText("Avançar");

        jbFinal.setText(">>");
        jbFinal.setToolTipText("Última");

        jlNomeCompleto.setText("Nome Completo:");

        jtfNomeCompleto.setNextFocusableComponent(jtfCpf);

        jtfEndereco.setNextFocusableComponent(jtfBairro);

        jlEndereço.setText("Endereço:");

        jtfBairro.setNextFocusableComponent(jtfCidade);

        jlBairro.setText("Bairro:");

        jLabel1.setText("CPF:");

        jlRG.setText("RG:");

        jlCidade.setText("Cidade:");

        jtfCidade.setNextFocusableComponent(jtfCep);

        jlCep.setText("Cep:");

        jtfCep.setNextFocusableComponent(jbImagem);

        jlDataNascimento.setText("Data de Nascimento:");

        jlSexo.setText("Sexo:");

        jcbSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione o sexo", "Masculino", "Feminino" }));
        jcbSexo.setToolTipText("");
        jcbSexo.setNextFocusableComponent(jtfEmail);

        jLabel3.setText("(dd/mm/aaaa)");

        jLabel2.setText("Email:");

        jtfEmail.setNextFocusableComponent(jtfTelefone);

        jlTelefone.setText("Telefone:");

        jlNomePai.setText("Nome do Pai:");

        jtfNomePai.setNextFocusableComponent(jtfNomeMae);

        jlNomeMae.setText("Nome da Mãe:");

        jtfNomeMae.setNextFocusableComponent(jcbSexo);

        jbImagem.setText("Inserir");
        jbImagem.setToolTipText("Inserir Imagem");
        jbImagem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mudaImagem(evt);
            }
        });

        try {
            jtfCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jtfCpf.setNextFocusableComponent(jtfRg);

        jtfRg.setNextFocusableComponent(jdcDataNascimento);

        jlImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetolions/Imagem.png"))); // NOI18N
        jlImagem.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jButton2.setText("...");
        jButton2.setToolTipText("Concluir");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Action(evt);
            }
        });

        jlDeMenor.setBackground(new java.awt.Color(0, 0, 0));

        jdcDataNascimento.setToolTipText("");
        jdcDataNascimento.setNextFocusableComponent(jtfNomePai);
        jdcDataNascimento.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jdcDataNascimentoMouseClicked(evt);
            }
        });

        try {
            jtfTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jtfTelefone.setNextFocusableComponent(jtfEndereco);

        javax.swing.GroupLayout jpCadPessoaLayout = new javax.swing.GroupLayout(jpCadPessoa);
        jpCadPessoa.setLayout(jpCadPessoaLayout);
        jpCadPessoaLayout.setHorizontalGroup(
            jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCadPessoaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpCadPessoaLayout.createSequentialGroup()
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jlDeMenor, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlNomeCompleto)
                            .addComponent(jLabel1)
                            .addComponent(jlRG)
                            .addComponent(jlDataNascimento)
                            .addComponent(jlNomePai)
                            .addComponent(jLabel2)
                            .addComponent(jlTelefone)
                            .addComponent(jlNomeMae)
                            .addComponent(jlSexo))
                        .addGap(18, 18, 18)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpCadPessoaLayout.createSequentialGroup()
                                .addComponent(jcbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(jpCadPessoaLayout.createSequentialGroup()
                                .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jpCadPessoaLayout.createSequentialGroup()
                                        .addComponent(jdcDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                                    .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jtfRg, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jtfCpf, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jtfNomeCompleto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jtfTelefone, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                                    .addComponent(jtfNomePai, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                                    .addComponent(jtfNomeMae, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                                    .addComponent(jtfEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE))
                                .addGap(10, 10, 10)
                                .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jpCadPessoaLayout.createSequentialGroup()
                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlBairro)
                                            .addComponent(jlCidade)
                                            .addGroup(jpCadPessoaLayout.createSequentialGroup()
                                                .addGap(10, 10, 10)
                                                .addComponent(jlCep)))
                                        .addGap(20, 20, 20))
                                    .addGroup(jpCadPessoaLayout.createSequentialGroup()
                                        .addComponent(jlEndereço)
                                        .addGap(18, 18, 18)))))
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jtfCep, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
                                .addComponent(jtfEndereco)
                                .addComponent(jtfCidade, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jtfBairro, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addComponent(jlImagem, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jpCadPessoaLayout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jbImagem)))
                        .addGap(28, 28, 28))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpCadPessoaLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jbNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbConsultar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jbAnterior)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbProximo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(21, 21, 21))
        );
        jpCadPessoaLayout.setVerticalGroup(
            jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCadPessoaLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbNovo)
                    .addComponent(jbConsultar)
                    .addComponent(jbSalvar)
                    .addComponent(jbExcluir)
                    .addComponent(jbProximo)
                    .addComponent(jbAnterior)
                    .addComponent(jbInicio)
                    .addComponent(jbFinal))
                .addGap(32, 32, 32)
                .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpCadPessoaLayout.createSequentialGroup()
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlNomeCompleto)
                            .addComponent(jtfNomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jtfCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlRG)
                            .addComponent(jtfRg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(jButton2))
                            .addComponent(jlDataNascimento)
                            .addComponent(jdcDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlNomePai)
                            .addComponent(jtfNomePai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(jpCadPessoaLayout.createSequentialGroup()
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlEndereço))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlBairro)
                            .addComponent(jtfBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlCidade)
                            .addComponent(jtfCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlCep)
                            .addComponent(jtfCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpCadPessoaLayout.createSequentialGroup()
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlNomeMae)
                            .addComponent(jtfNomeMae, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlSexo)
                            .addComponent(jcbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jtfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpCadPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlTelefone)
                            .addComponent(jtfTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jlDeMenor, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jlImagem, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbImagem, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(48, Short.MAX_VALUE))
        );

        getContentPane().add(jpCadPessoa, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mudaImagem(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mudaImagem

        File arq = null;

        this.jfcImagem.setCurrentDirectory(new File("C:/Users/rti dev-01/Documents/NetBeansProjects/ProjetoLions/src/projetolions"));

        int res = this.jfcImagem.showOpenDialog(this);

        if (res == this.jfcImagem.APPROVE_OPTION){
            arq = this.jfcImagem.getSelectedFile();
        }

        this.jlImagem.setIcon(new ImageIcon(arq.getAbsolutePath()));

        //this.jlImagem.setIcon(new ImageIcon(getClass().getResource(arq.getName().toString())));
        //*getName* retorna nome sem o caminho por isso está errado O certo seria este *getAbsolutePath*
        
}//GEN-LAST:event_mudaImagem
    private void Salvar(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Salvar

        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/projetoLions";
        String inserir;
        cad_pessoa a = new cad_pessoa();

        a.setNomeCompleto(this.jtfNomeCompleto.getText());
        a.setCPF(this.jtfCpf.getText());
        a.setRG(this.jtfRg.getText());
        a.setEndereco(this.jtfEndereco.getText());
        a.setBairro(this.jtfBairro.getText());
        a.setCidade(this.jtfCidade.getText());
        a.setCep(this.jtfCep.getText());
        a.setDataNascimento(this.jdcDataNascimento.getDate());
        a.setSexo(String.valueOf(this.jcbSexo.getSelectedItem()));
        a.setEmail(this.jtfEmail.getText());
        a.setTelefone(this.jtfTelefone.getText());

        if (grav == 1){
            a.setNomePai(this.jtfNomePai.getText());
            a.setNomeMae(this.jtfNomeMae.getText());
        }


        inserir = "insert into cadPessoa(nomeCompleto, cpf, rg, datanascimento"+
                "nomepai, nomemae, sexo, email, telefone, endereco, bairro"+
                "cidade, cep) values ('"+a.getNomeCompleto()+"','"+
                a.getCPF()+"','"+
                a.getRG()+"','"+
                a.getDataNascimento()+"','"+
                a.getNomePai()+"','"+
                a.getNomeMae()+"','"+
                a.getSexo()+"','"+
                a.getEmail()+"','"+
                a.getTelefone()+"','"+
                a.getEndereco()+"','"+
                a.getBairro()+"','"+
                a.getCidade()+"','"+
                a.getCep()+"')";


        Connection conn = null;
        Statement stm = null;
        try{
            Class.forName(driver);
            conn = DriverManager.getConnection(url, "root","root");
            stm = conn.createStatement();
            stm.execute(inserir);
            conn.commit();
            conn.close();
        }
        catch(SQLException e){
            JOptionPane.showMessageDialog(this, "Problemas com as informações que foram enviadas ao banco de dados");
            e.printStackTrace();
        }
        catch(ClassNotFoundException e){
            JOptionPane.showMessageDialog(this, "O driver de conexão com o banco de dados não foi encontrado\nContacte o suporte técnico!");
            e.printStackTrace();
        }

    }//GEN-LAST:event_Salvar

    private void Action(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Action
        
        Date dataAtual = new Date();
        Date nascimento = this.jdcDataNascimento.getDate();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        int ano1 = Integer.parseInt(sdf.format(nascimento));
        int ano2 = Integer.parseInt(sdf.format(dataAtual));
        int dif = ano2 - ano1;
        this.jlDeMenor.setText("Idade: "+dif);

        if (dif < 18)
        {
        this.jtfNomePai.setVisible(true);
        this.jtfNomeMae.setVisible(true);
        this.jlNomePai.setVisible(true);
        this.jlNomeMae.setVisible(true);
        this.grav = 1;
        }
        else
        {
        this.jtfNomePai.setVisible(false);
        this.jtfNomeMae.setVisible(false);
        this.jlNomePai.setVisible(false);
        this.jlNomeMae.setVisible(false);
        }
           
    }//GEN-LAST:event_Action

    private void jdcDataNascimentoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jdcDataNascimentoMouseClicked

        if (!this.isMenorIdade(this.jdcDataNascimento.getDate()))
        {
        this.jtfNomePai.setVisible(true);
        this.jtfNomeMae.setVisible(true);
        this.jlNomePai.setVisible(true);
        this.jlNomeMae.setVisible(true);
        this.grav = 1;
        }
        else
        {
        this.jtfNomePai.setVisible(false);
        this.jtfNomeMae.setVisible(false);
        this.jlNomePai.setVisible(false);
        this.jlNomeMae.setVisible(false);
        }
    }//GEN-LAST:event_jdcDataNascimentoMouseClicked
  
       public static boolean isMenorIdade(Date nascimento)
        {
         Calendar dezoitoAnosAtras = new GregorianCalendar();
         dezoitoAnosAtras.add(Calendar.YEAR, -18);
         return nascimento.after(dezoitoAnosAtras.getTime());
        } 
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new cadPessoa().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JButton jbAnterior;
    private javax.swing.JButton jbConsultar;
    private javax.swing.JButton jbExcluir;
    private javax.swing.JButton jbFinal;
    private javax.swing.JButton jbImagem;
    private javax.swing.JButton jbInicio;
    private javax.swing.JButton jbNovo;
    private javax.swing.JButton jbProximo;
    private javax.swing.JButton jbSalvar;
    private javax.swing.JComboBox jcbSexo;
    private com.toedter.calendar.JDateChooser jdcDataNascimento;
    private javax.swing.JFileChooser jfcImagem;
    private javax.swing.JLabel jlBairro;
    private javax.swing.JLabel jlCep;
    private javax.swing.JLabel jlCidade;
    private javax.swing.JLabel jlDataNascimento;
    private javax.swing.JLabel jlDeMenor;
    private javax.swing.JLabel jlEndereço;
    private javax.swing.JLabel jlImagem;
    private javax.swing.JLabel jlNomeCompleto;
    private javax.swing.JLabel jlNomeMae;
    private javax.swing.JLabel jlNomePai;
    private javax.swing.JLabel jlRG;
    private javax.swing.JLabel jlSexo;
    private javax.swing.JLabel jlTelefone;
    private javax.swing.JPanel jpCadPessoa;
    private javax.swing.JTextField jtfBairro;
    private javax.swing.JTextField jtfCep;
    private javax.swing.JTextField jtfCidade;
    private javax.swing.JFormattedTextField jtfCpf;
    private javax.swing.JTextField jtfEmail;
    private javax.swing.JTextField jtfEndereco;
    private javax.swing.JTextField jtfNomeCompleto;
    private javax.swing.JTextField jtfNomeMae;
    private javax.swing.JTextField jtfNomePai;
    private javax.swing.JFormattedTextField jtfRg;
    private javax.swing.JFormattedTextField jtfTelefone;
    // End of variables declaration//GEN-END:variables

   // cad_pessoa a = new cad_pessoa();
    int grav = 0;
}
